home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Loadstar 10
/
010.d81
/
dos #26
< prev
next >
Wrap
Text File
|
2022-08-26
|
2KB
|
89 lines
DOS and don'ts -- Part 26
by Jimmy Weiler
Now let's get into some READing.
Reading from a RELative file is almost
the same as writing to it. The most
significant difference is that you use
INPUT# or GET# in place of PRINT#.
The technique you use is:
1. Send a position command to access
a particular record and character.
2. Input from the file.
Let's read the name and number out
of record 2.
10 OPEN 15,8,15
20 OPEN 3,8,4,"PHONEFILE,L,"+CHR$(89)
30 RN=2:rem record number
40 HB=INT (RN/256):rem high & low byte
50 LB=RN-(HB*256) :rem of record #'s
60 PRINT#15,"P"CHR$(4)CHR$(LB)CHR$(HB)
CHR$(1):rem position to rec RN
70 INPUT#3,NAME$ :rem input name and
80 INPUT#3,NUMBER$ :rem address
90 CLOSE3
100 PRINT NAME$"'s phone number is ";
NUMBER$;"."
110 CLOSE15
This technique works fine for reading
a record that has no commas, quotes,
or colons in its text. If you had to
be able to read past those separators,
you would use GET# instead of INPUT#.
70 NAME$=""
71 GET#3,T$:IF T$<>CHR$(13)THEN NAME$=
NAME$+T$:GOTO 71
80 NUMBER$=""
81 GET#3,T$:IF T$<>CHR$(13)THEN
NUMBER$=NUMBER$+T$:GOTO 81
You may have noticed that we only
used one POSITION command to do an
INPUT# from our PHONEFILE. Unlike
PRINT#, INPUT# keeps track of where
it is in a record. Every INPUT#
begins where the previous one left off
and reads data from the file until it
comes to the next carriage return.
INPUT# also accepts multiple
variable arguments -- you can use
INPUT#3,A$:INPUT#3,B$ or INPUT#3,A$,B$
and achieve the same effect.
------ continued in Part 27 ---------